﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AddNewTopUp : System.Web.UI.Page
{
    private ServiceBlo _blo = new ServiceBlo();
    private ServiceDetail _serviceDetail;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblStatus.Visible = false;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            bool status=false;
            if (rbtnActive.Checked)
	        {
		        status=true;
	        }
            _serviceDetail = new ServiceDetail(1, "", 0, int.Parse(txtDuration.Text.ToString()), "", int.Parse(txtDiscount.Text.ToString()),
            float.Parse(txtDenomination.Text.ToString()), float.Parse(txtTotal.Text.ToString()),status);
        }
        catch (Exception)
        {
            lblStatus.Visible = true;
            lblStatus.Text = "Your data is not valid! Please try again";
            return;
        }        
        _blo.InsertServiceDetail(_serviceDetail);
        Response.Redirect("TopUpManager.aspx");
    }
    protected void txtDuration_TextChanged(object sender, EventArgs e)
    {
        if (!txtDiscount.Text.Equals("") && !txtDenomination.Text.Equals("") && !txtDuration.Text.Equals(""))
        {
            float total = float.Parse(txtDenomination.Text.ToString()) * int.Parse(txtDuration.Text.ToString()) 
                            * (100 - int.Parse(txtDiscount.Text.ToString())) / 100;
            txtTotal.Text = total.ToString();
        }
        if (txtDuration.Text.Equals(""))
        {
            txtDuration.Focus();
        }
        else if (txtDenomination.Text.Equals(""))
        {
            txtDenomination.Focus();   
        }
        else if (txtDiscount.Text.Equals(""))
        {
            txtDiscount.Focus();
        }
    }
}